<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once('lib.php');

/**
 * Tra ve cach xep loai sinh vien theo diem
 * @param $m diem cua sinh vien
 */
function xeploai($m)
{
    if ($m>=90 && $m<=100) return get_string("xuatsac","diemrenluyen");
    if ($m>=80 && $m<=89) return get_string("tot","diemrenluyen");
    if ($m>=70 && $m<=79) return get_string("kha","diemrenluyen");
    if ($m>=60 && $m<=69) return get_string("trungbinhkha","diemrenluyen");
    if ($m>=50 && $m<=59) return get_string("trungbinh","diemrenluyen");
    if ($m>=30 && $m<=49) return get_string("yeu","diemrenluyen");
    if ($m<30) return get_string("kem","diemrenluyen");
}
/**
 * Kiem tra du diem khi nhap vao cua co dung dang hay khong
 * @param $student - Du lieu ve diem cua sinh vien
 */
function validate_diemrenluyen($student){
    $d1 = intval($student->d1);
    $d2 = intval($student->d2);
    $d3 = intval($student->d3);
    $d4 = intval($student->d4);
    $d5 = intval($student->d5);

    if (strval($d1) == $student->d1 && strval($d2) == $student->d2 && strval($d3) == $student->d3
            && strval($d4) == $student->d4 && strval($d5) == $student->d5 )
    {
        if ($d1>=0 && $d1<=30 && $d2>=0 && $d2<=25 && $d3>=0 && $d3<=20 && $d4>=0 && $d4<=15 && $d5>=0 && $d5<=10) {
            return true;
        } else {return false;}
    } else {return false;}
    return true;
}
/**
 *  In ra du lieu chon thang, nam cho viec quan ly theo thang
 * @param $month ten cua hop chon thang thang
 * @param $year ten cua hop chon nam
 * @param $currenttime - Thoi gian de in ra, mac dinh 0 se dung thoi gian hien ta.
 * @param $return True Tra ve du lieu. False - In ra du lieu
 */
function print_month_selector($month, $year, $currenttime=0, $return=false) {

    if (!$currenttime) {
        $currenttime = time();
    }
    $currentdate = usergetdate($currenttime);

    for ($i=1; $i<=12; $i++) {
        $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
    }
    for ($i=2010; $i<=2040; $i++) {
        $years[$i] = $i;
    }

    // Build or print result
    $result='';
    // Note: There should probably be a fieldset around these fields as they are
    // clearly grouped. However this causes problems with display. See Mozilla
    // bug 474415
    $result.='<label class="accesshide" for="menu'.$month.'">'.get_string('month','form').'</label>';
    $result.=choose_from_menu($months, $month, $currentdate['mon'],  '', '', '0', true);
    $result.='<label class="accesshide" for="menu'.$year.'">'.get_string('year','form').'</label>';
    $result.=choose_from_menu($years,  $year,  $currentdate['year'], '', '', '0', true);

    if ($return) {
        return $result;
    } else {
        echo $result;
    }
}


/**
 * In ra cac tab manage hoac export
 */
function show_tabs($cm, $context, $currenttab='manage')
{
	$toprow = array();
    if (has_capability('mod/diemrenluyen:takemark', $context)) {
        $toprow[] = new tabobject('manage', 'manage.php?id='.$cm->id,
                    get_string('manage','diemrenluyen'));
    }

    if (has_capability('mod/diemrenluyen:export', $context)) {
	    $toprow[] = new tabobject('export', 'export.php?id='.$cm->id,
	                get_string('export','diemrenluyen'));
    }
    $tabs = array($toprow);
    print_tabs($tabs, $currenttab);
}

?>
